package org.tang.stock;

import java.util.ArrayList;
import java.util.List;

public class MASlope {
	int ma;//均线参数
	private List<Stock> stocks;
	private int  sum[];
	List<Slope> slopes = new ArrayList<Slope>();
	public MASlope(List<Stock> stocks){
		this(stocks,10);
	}
	public MASlope(List<Stock> stocks,int ma){
		this.ma = ma;
		this.stocks = stocks;
		this.sum = new int[stocks.size()];
		parseSlope();
	}
	
	private void parseSlope() {
		for(int i =0;i<31;i++){
			Slope slope = new Slope();
			slope.slope = 0.97+0.002*i;
			slopes.add(slope);
		}
		for(int i =0 ; i< this.stocks.size() - ma-1; i++){
			int sum1 =0;
			int sum2 = 0;
			for(int j=0;j<ma;j++){
				sum1 +=stocks.get(i+j).getClosePrice();
				sum2 +=stocks.get(i+j+1).getClosePrice();
			}
			int t = (int)Math.floor((sum1*1.0/sum2-0.97)/0.002);
			slopes.get(t).stocks.add(stocks.get(i));
			slopes.get(t).count ++;
			
		}
	}
	public List<Slope> getSlopes(){
		return slopes;
	}
}
class Slope {
	double slope;//斜率
	double deviate;//偏离值
	int count;//命中次数
	List<Stock> stocks = new ArrayList<Stock>();
}
